package com.achieve.wx.controller;

import com.achieve.wx.domain.WechatGenerateQrCodeParam;
import com.achieve.wx.domain.WechatGenerateShortLinkParam;
import com.achieve.wx.service.WxMaManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/wx/ma")
public class WxMaController {
    @Autowired
    private WxMaManagerService wxMaManagerService;

    /**
     * 生成小程序码
     */
    @GetMapping("/qrcode")
    public byte[] getWxaCode(@RequestParam(defaultValue = "default") String appKey,
                             @RequestParam String path) {
        WechatGenerateQrCodeParam param = new WechatGenerateQrCodeParam();
        param.setPage(path);
        param.setAppKey(appKey);
        return wxMaManagerService.createWxaCode(param);
    }

    /**
     * 生成短链接
     */
    @GetMapping("/shortLink")
    public String getShortLink(@RequestParam(defaultValue = "default") String appKey,
                              @RequestParam String pageUrl) {
        WechatGenerateShortLinkParam param = new WechatGenerateShortLinkParam();
        param.setAppKey(appKey);
        param.setPageUrl(pageUrl);
        return wxMaManagerService.createShortLink(param);
    }
}
